﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Configuration;
using Top.Api;
using Top.Api.Domain;
using Top.Api.Request;
using Top.Api.Response;
using System.Collections;

namespace KSGJ.AjaxCommand
{
    /// <summary>
    /// getgoodurl 的摘要说明
    /// </summary>
    public class getgoodurl : IHttpHandler, System.Web.SessionState.IRequiresSessionState
    {
        private static ITopClient client = new DefaultTopClient(WebConfigurationManager.AppSettings["AppUrl"].ToString(), WebConfigurationManager.AppSettings["AppKey"].ToString(), WebConfigurationManager.AppSettings["AppSecret"].ToString());

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string goodid = context.Request.Form["goodid"];
            ItemGetRequest itemreq = new ItemGetRequest();
            itemreq.Fields = "detail_url";
            itemreq.NumIid = long.Parse(goodid);
            //itemreq. = context.Session["sessionKey"].ToString();
            ItemGetResponse itemrep = client.Execute(itemreq);
            if (!itemrep.IsError)
            {
                context.Response.Write(itemrep.Item.DetailUrl);
                context.Response.End();
            }
            else
            {
                context.Response.Write("链接复制失败，请稍后再试!");
                context.Response.End();
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}